﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;

namespace Hangout.Web.Core.Accounts
{
    public class Foursquare
    {
        public static bool HasFoursquareData(int userid,Model.HangoutDBEntities context)
        {
            if (context.FoursquareDatas.Where(o => o.UserID == userid).SingleOrDefault() == null)
            {
                return false;
            }

            return true;
        }

        public static bool HasFoursquareData(string accessToken, Model.HangoutDBEntities context)
        {
            if (context.FoursquareDatas.Where(o => o.AccessToken == accessToken).SingleOrDefault() == null)
            {
                return false;
            }

            return true;
        }

        public static AccountStatus InsertFoursquareData(string accesstoken,Model.HangoutDBEntities context)
        {
            if (!HasFoursquareData(accesstoken, context))
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"https://api.foursquare.com/v2/users/self?oauth_token="+accesstoken+"&v=20121116");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                JObject obj = JObject.Parse(new StreamReader(response.GetResponseStream()).ReadToEnd());

                

            }

            return AccountStatus.Error;
        }
    }
}